package com.zs4sdk.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.zs4sdk.Zs4GameBase;
import com.zs4sdk.Zs4GameMenu;
import com.zs4sdk.common.Extra;
import com.zs4sdk.extra.Zs4GameCode;
import com.common.library.util.ActivityHelper;
import com.common.library.util.Helper;
import com.common.library.util.LogUtil;

/**
 *
 * function: 公告页面
 *
 * @ author: aXiBa
 */
public class Zs4GameVoucherResultActivity extends Zs4GameBaseActivity {

	public static final String TAG = Zs4GameVoucherResultActivity.class.getSimpleName();

	TextView mTitleView;
	TextView mDescView;
	Button mKefuButton;
	Button mGotoGameSuccessButton;
	Button mGotoGameFailButton;
	String pay_result_desc = "";
	int SUCCESS = 3;



	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(ActivityHelper.getLayoutResId("zs4gamelayout_view_pay_result"));
		getParams();

		init();
	}

	private void getParams() {

		Intent intent = getIntent();
		if (Helper.isNotNull(intent)) {
			if (intent.hasExtra(Extra.INTENTKEY.INTENT_TYPE)) {
				SUCCESS = intent.getIntExtra(Extra.INTENTKEY.INTENT_TYPE,3);
			}
			if (intent.hasExtra(Extra.INTENTKEY.BACKSENDMESSAGE)) {
				pay_result_desc = intent.getStringExtra(Extra.INTENTKEY.BACKSENDMESSAGE);
			}
		}
	}


	protected void init() {

		initReferences();


	}


	private void initReferences() {

		LogUtil.e("ping====",this.mScreenOrientation+"");

		mTitleView = (TextView) findViewById(ActivityHelper.getIdResId("zs4gameviewid_mTitleView_view_pay_result"));
		mDescView = (TextView) findViewById(ActivityHelper.getIdResId("zs4gameviewid_view_pay_result_desc"));
		mKefuButton = (Button) findViewById(ActivityHelper.getIdResId("zs4gameviewid_btn_pay_result_kefu"));
		mGotoGameFailButton = (Button) findViewById(ActivityHelper.getIdResId("zs4gameviewid_btn_pay_fail_result_goto_game"));
		mGotoGameSuccessButton = (Button) findViewById(ActivityHelper.getIdResId("zs4gameviewid_btn_pay_success_result_goto_game"));
		//参数异常
		if (SUCCESS == 3){
			mTitleView.setText(ActivityHelper.getStringResId("zs4gamestring_pay_result_unknown"));
			mDescView.setText(ActivityHelper.getStringResId("zs4gamestring_pay_result_receive_parame_exception"));
			mKefuButton.setVisibility(View.VISIBLE);
			mGotoGameFailButton.setVisibility(View.VISIBLE);
			mGotoGameSuccessButton.setVisibility(View.GONE);
		}
		//支付成功
		else if(SUCCESS == Extra.JSONReturnResult.SUCCESS){
			mTitleView.setText(ActivityHelper.getStringResId("zs4gamestring_pay_result_success"));
			mDescView.setText(ActivityHelper.getStringResId("zs4gamestring_pay_result_success_desc"));
			mKefuButton.setVisibility(View.GONE);
			mGotoGameFailButton.setVisibility(View.GONE);
			mGotoGameSuccessButton.setVisibility(View.VISIBLE);
		}
		///支付失败
		else if(SUCCESS == Extra.JSONReturnResult.FAIL){
			mTitleView.setText(ActivityHelper.getStringResId("zs4gamestring_pay_result_failed"));
			mDescView.setText("支付失败原因："+pay_result_desc);
			mKefuButton.setVisibility(View.VISIBLE);
			mGotoGameFailButton.setVisibility(View.VISIBLE);
			mGotoGameSuccessButton.setVisibility(View.GONE);
		}

		setViewClickEvent(this, ActivityHelper.getIdResId("zs4gameviewid_btn_pay_result_kefu"),
				ActivityHelper.getIdResId("zs4gameviewid_btn_pay_fail_result_goto_game"),
				ActivityHelper.getIdResId("zs4gameviewid_btn_imv_goto_game"),
				ActivityHelper.getIdResId("zs4gameviewid_btn_pay_success_result_goto_game"));

	}

	@Override
	public void onClick(View v) {
		super.onClick(v);
		int id = v.getId();
		if (ActivityHelper.getIdResId("zs4gameviewid_btn_pay_result_kefu") == id) {
			//到客服
//			Zs4GameBase.getInstance().showCustomerService(this);
			Zs4GameMenu.showWebView(this,
					"在线客服",
					Extra.URL.SDKGAME_FEEDBACK,
					flag,
					"3");
			finish();
		} else if (ActivityHelper.getIdResId("zs4gameviewid_btn_pay_fail_result_goto_game") == id||
				ActivityHelper.getIdResId("zs4gameviewid_btn_pay_success_result_goto_game") == id||
				ActivityHelper.getIdResId("zs4gameviewid_btn_imv_goto_game") == id) {
			//返回游戏
			ActivityHelper.sendBroadcast(Zs4GameBase.getPackageName().concat(Extra.ACTIONKEY.MESSAGE_POSTFIX), Zs4GameCode.BACKTOGAME, this);
			Zs4GameMenu.closeActivitysAndShowStartMenu(this, flag);
//			backToGame();
		}
	}


	// 不能后退
	@Override
	public void onBackPressed() {

	}
}
